package com.example.seakdreamandroid.crosstalk;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.example.seakdreamandroid.C;
import com.example.seakdreamandroid.MainActivity;
import com.example.seakdreamandroid.R;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.List;

public class Crosstalk extends AppCompatActivity {
    private TextView category;
    private TabLayout tabLayout;
    private ViewPager2 vp2;
    private ImageView returnMain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_crosswalk);

        getViews();
        vp2.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        category.setText("相声");
        returnMain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Crosstalk.this, MainActivity.class);
                startActivity(intent);
            }
        });
        List<Fragment> fragments=setData();
        MyFragmentAdapter adapter = new MyFragmentAdapter(
                fragments, this
        );
        vp2.setAdapter(adapter);
        TabLayoutMediator mediator = new TabLayoutMediator(
                tabLayout,
                vp2,
                new TabLayoutMediator.TabConfigurationStrategy() {
                    @Override
                    public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                        switch (position) {
                            case 0://第一个标签
                                tab.setText("精选");

                                break;
                            case 1://第二个标签
                                tab.setText("单口");

                                break;
                            case 2://第三个标签
                                tab.setText("对口");
                                break;

                        }
                    }
                }
        );
        mediator.attach();
    }
    private List<Fragment> setData() {
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new Fragment1());
        fragments.add(new Fragment2());
        fragments.add(new Fragment3());
        return fragments;
    }
    private void getViews() {
        category = findViewById(R.id.category);
        tabLayout = findViewById(R.id.tablayout);
        vp2 = findViewById(R.id.vp2);
        returnMain = findViewById(R.id.return_tomain);
    }
}